// pages/orgAccount/orgAccount.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orgid:'',
    item:'',
    adminTel:'',
    isOrg: '',
    managerAuthList: false,
  },
  tocheck(){
    wx.navigateTo({
      url: '/pages/check/check?orgId=' + this.data.orgid + '&isOrgCheck=1'
    })
  },
  tomoney(){
    wx.navigateTo({
      url: '/pages/collectMoney/collectMoney?orgId=' + this.data.orgid + '&orgMoney=' + this.data.item.orgAccountBalance
    })
  },
  topage(e){
    var dataset = e.currentTarget.dataset;
    var url = dataset.ture;
    if (dataset.type){
      wx.navigateTo({
        url: url + '?id=' + this.data.orgid + '&type=' + dataset.type + '&cashApplyNumber=' + this.data.item.cashApplyNumber + '&adminTel=' + this.data.adminTel
      })
    }else{
      wx.navigateTo({
        url: url + '?id=' + this.data.orgid + '&name=' + this.data.item.orgName
      })
    }
   
  },
  topage1(){
    wx.navigateTo({
      url: "/pages/hfjnList/hfjnList?id=" + this.data.orgid + '&isOrg=' + this.data.isOrg + "&managerAuthList=" + this.data.managerAuthList
    })
  },
  getOrgCashInfo(){
    var that = this
    app.req({
      url: "orgmini/orgAccount/getOrgCashInfo",
      data: {
        orgId: that.data.orgid,
      },
      success: function (res) {
        if (200 == res.code) {
          that.toggle('item', res.data)
          that.toggle('adminTel', res.data.adminTel)
        }
      }
    })
  },
  onSwitchChange(){
    var that = this
    if (that.data.item.isAccountSeeAdmin==0){
      wx.showModal({
        content: '打开后，只有指定人员才能查看组织账户',
        confirmColor:'#2168EB',
        success(res) {
          if (res.confirm) {
            app.req({
              url: "orgmini/orgAccount/updateOrgAccount",
              data: {
                orgId: that.data.orgid,
                status: 1,
                isAccountSeeAdmin: 0,
      },
              success: function (res) {
                if (200 == res.code) {
                  that.toggle('item.isAccountSeeAdmin', 1)
                }
              }
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }else{
      app.req({
        url: "orgmini/orgAccount/updateOrgAccount",
        data: {
          orgId: that.data.orgid,
          status: 0,
          isAccountSeeAdmin: 1,
        },
        success: function (res) {
          if (200 == res.code) {
            that.toggle('item.isAccountSeeAdmin', 0)
          }
        }
      })
    }
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.toggle('orgid', options.id)
    that.toggle("isOrg", options.isOrg);
    that.toggle("managerAuthList", options.managerAuthList);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getOrgCashInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})